package com.wsl.Service.impl;

import com.wsl.Entity.Person;
import com.wsl.Repository.PersonRepository;
import com.wsl.Service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * @Author:WangShuliang
 * @Description:
 * @Date:Created in 16:31 2017/11/29
 * @Modified by:
 */
@Service
public class DemoServiceImpl implements DemoService {
    @Autowired
    PersonRepository personRepository;
    @Override
    @CachePut(value = "people",key = "#person.id")
    public Person save(Person person) {
        Person p = personRepository.save(person);
        System.out.println("为id,key为:"+p.getId()+"数据做了缓存");
        return p;
    }

    @Override
    public void remove(Long id) {

    }

    @Override
    @Cacheable(value="people",key = "#person.id")
    public Person findOne(Person person) {
        Person p = personRepository.findOne(person.getId());
        System.out.println("为id、key为:"+p.getId()+"数据做了缓存");
        return p;
    }
}